package com.zcup.designer.behavior.iterator;


public class ConcreteIterator extends Iterator{
    private final ConcreteAggregate aggregate;
    private int current;

    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    Object first() {
        return aggregate.get(0);
    }

    @Override
    Object next() {
        Object ret = null;
        current++;
        if (current < aggregate.count()) {
            ret = aggregate.get(current);
        }
        return ret;
    }

    @Override
    boolean isDone() {
        return current >= aggregate.count();
    }

    @Override
    Object currentItem() {
        return aggregate.get(current);
    }
}
